import {
  $http
} from '@escook/request-miniprogram'

import store from '@/store/store.js'

//配置请求根路径
$http.baseUrl = 'https://api-hmugo-web.itheima.net/';
//请求拦截器
$http.beforeRequest = function (options) {
  uni.showLoading({
    title: '加载中...',
    mask: true
  })
  //在请求拦截器中判断当前接口是否设置了权限，如果有权限，需要携带token
  
  if(options.url.indexOf('/my/')!==-1){
    options.header.Authorization=store._state.data.m_user.token;
    return options
  }
};


//响应拦截器
$http.afterRequest = function (options) {
  //关闭loading提示框
  uni.hideLoading();
}

export const escook = $http;